package com.ark.controller.admin;

import com.ark.constant.ShopConstant;
import com.ark.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Tag(name = "店铺相关接口")
public class ShopController {

    private final RedisTemplate<String,Object> redisTemplate;

    public ShopController(RedisTemplate<String,Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @PutMapping("/{status}")
    @Operation(summary = "设店铺营业状态")
    public Result<?> update(@PathVariable Integer status){
        log.info("设置店铺营业状态: {}",status);
        redisTemplate.opsForValue().set(ShopConstant.SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/status")
    @Operation(summary = "获取店铺营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get(ShopConstant.SHOP_STATUS);
        log.info("获取到店铺的营业状态为: {}",status);
        return Result.success(status);
    }


}
